package com.linlang.grasharepro.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.linlang.grasharepro.R;
import com.linlang.grasharepro.model.NewMessageDomain;
import com.linlang.grasharepro.model.ShareCoenten;

import java.util.List;

/**
 * 商家WIFI适配器
 * Created by pengtao on 2016/6/3.
 */
public class ChatAdapter extends BaseAdapter {

    /**
     * 分享信息列表
     */
    private List<NewMessageDomain> list;

    public List<NewMessageDomain> getList() {
        return list;
    }

    public void setList(List<NewMessageDomain> list) {
        this.list = list;
    }

    public Context getCtx() {
        return ctx;
    }

    public void setCtx(Context ctx) {
        this.ctx = ctx;
    }



    private Context ctx;

    public ChatAdapter(List<NewMessageDomain> list, Context ctx) {
        this.list = list;
        this.ctx = ctx;
        // 实例化获取图片的类
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Holder hold;
        if (convertView == null) {
            hold = new Holder();
            convertView = View.inflate(ctx, R.layout.item_chat, null);
            hold.mText = (TextView) convertView.findViewById(R.id.chat_text);//标题
            hold.mTime = (TextView) convertView.findViewById(R.id.item_grid_text);//
            hold.mHead = (ImageView) convertView.findViewById(R.id.chat_image);
            convertView.setTag(hold);
        } else {
            hold = (Holder) convertView.getTag();
        }

        if (list != null && list.size() > 0) {
            NewMessageDomain newMessageDomain = list.get(position);
            hold.mText.setText(newMessageDomain.getContent());
            hold.mTime.setText(newMessageDomain.getTime());
        }
    return convertView;
}

    static class Holder {
        TextView mText;
        ImageView mHead;
        TextView mTime;
    }
}
